import { createRouter, createWebHashHistory } from "vue-router";
import Home from "../views/Home";

const routes = [
  //  路由重定向
  {
    path: '/home',
    redirect: '/',
  },
  //  重定向可以同时传值
  {
    path:"/pt",
    redirect:{path:"/product",query:{proName:"第二只冰棍",}}
  },

  {path:"/",
  component:Home
  },
  {
    path: "/product",
    //面试题:如何优化vue项目首屏加载速度? 下列就是其中一种方式叫做"懒加载路由"
    component:()=>import("../views/Product")
  },
  {
    path: "/Cart/:id/:num/:price",
    //面试题:如何优化vue项目首屏加载速度? 下列就是其中一种方式叫做"懒加载路由"
    component:()=>import("../views/Cart"),
    name:'c'
  },
  //  个人信息组件
  {
    path:"/mine",
    component:()=>import("../views/Mine"),
    beforeEnter:(to,from ,next)=>{
      console.log("================")
      next();
    },
  //  切换二级路由,需要在以及路由使用children字段
    children:[
    //    二级的路由不以斜杠开头
      {
        path:"info",
        component:()=>import("../components/Personinfo"),
        meta:{requestLogin:true},
      },
      {
        path:"order",
        component:()=>import("../components/Order"),
        meta:{requestLogin:true},
      }

    ]


  },
  //  新闻模块
  {
    path: "/news",
    component:()=>import("../views/News"),
    children:[{
        path:"hot",
        component:()=>import("../components/Hot")
      },
      {
        path:"girl",
        components:{
          default:()=>import("../components/girl"),
          a:()=>import("../components/Comment")
        }
      }
    ]

  },



  {
    path: "/:pathMatch(.*)",
    component:()=>import("../views/Non"),

  }

];

const router = createRouter({
  history: createWebHashHistory(),
  routes
});

export default router;
